import telebot
import logging
from telebot import apihelper
from readconfig import config
from send import send
import ast

flag=0
send_ms =''
logger = telebot.logger
config = config()
send = send(config.get_pushTOKEN(), config.get_topic())
telebot.logger.setLevel(logging.DEBUG)

if config.get_proxy() == '':
    pass
else:
    apihelper.proxy = ast.literal_eval(config.get_proxy())

bot = telebot.TeleBot(config.get_TOKEN(), parse_mode="MARKDOWN")


@bot.message_handler(commands=['help'])
def send_welcome(m):
    bot.send_message(m.chat.id, f'你的信息{m.chat.id}')


@bot.message_handler(commands=['start'])
def start_send(m):
    global flag
    flag = 1
    bot.send_message(m.chat.id, "开始发送")


@bot.message_handler(commands=['stop'])
def start_send(m):
    global flag
    global send_ms
    flag = 0
    bot.send_message(m.chat.id, "停止发送")
    send.pushplus_bot(send_ms)


@bot.message_handler(func=lambda message: True)
def echo_all(m):
    global flag
    global send_ms
    if flag:
        send_ms=send_ms+m.text
        bot.send_message(m.chat.id, "接收成功")
    else:bot.send_message(m.chat.id, "please send /start")


bot.polling()
